{#include file="top.php"#}
<script type="text/javascript">
    function ajax_fb_ponits(){
        
        
        $.ajax({
            url : '/ajax_points.php?action=ajax_fb_points',
            type : 'POST',
            data: "code={#php#}echo md5('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'imoreHK');{#/php#}&action_name=share_product_invite&remark={#str_replace("'","’",$product.cname)#}",
            dataType : 'json',
            success: function(data){
                if(data.ret==0){
                    // console.info("未登入");
                }else if(data.ret==1){
                    if(data.data.ret==1){
                        // console.info(data.data.action);
                    }else{
                        //  console.info(data.data.reason);
                    }
                    
                }else{
                    // console.info(data.reason);
                }
            }
        });
        $("#facebook").val(1);
        $("#click_fb").addClass('checked');
        $("#click_fb").attr("onclick","");
    }
    function callback(content){
        switch(content['retcode']){
            case 1:
            case 2:
            case 3:
            case 4:
            case 6:
                $('#mark'+content['retcode']).html('<a class="ir close">close</a>'+content['msg']);
                window.scrollTo(0,600);
                break;
            case 7:
                $('#mark'+content['retcode']).html('<a class="ir close">close</a>'+content['msg']);
                window.scrollTo(0,900);
                break;
            case 5:
                $('#mark5_'+content['data']['k']).html('<a class="ir close">close</a>'+content['msg']);
                break;
            case 8:
                showLB('#dialog1',0);
                break;
            case 9:
                showpop(content['msg']);
                break;
            case 10:
                showLB('#dialog',0);
                break;
            default:
                break;
        }
    }

    function showLB(ct,n){
        var sh=$(document).height();
        var sw=$(document).width();
        var st=$(window).scrollTop();
        var ch=$(window).height();
        var cw=$(window).width();
        var tbT=(Number(ch)/3+Number(st))+"px";
        var tbL=(Number(cw)/2)+"px";
        if(n==0){
            $("#fullbg").css({width:sw,height:sh});
            $(ct).css({top:tbT,left:tbL});
            $("#fullbg").fadeTo('slow', 0.4);
            $(ct).fadeIn('slow');
            $(window).scroll(function(){showLB(ct,1)});
            $(window).resize(function(){showLB(ct,1)});
        }else{
            if($("#fullbg").css("display")=="block"){
                $("#fullbg").css({width:sw,height:sh});
                $(ct).css({top:tbT,left:tbL});
            }
        }
    }

    function closeLB(){
        $("#fullbg").fadeOut('slow');
        $("#dialog").fadeOut('slow');
        $("#dialog1").fadeOut('slow');
        $("#dialog_popup").fadeOut('slow');
        $("#dialog_limits").fadeOut('slow');
    }

    function phide(s){
        $('#'+s).empty();
    }

    function click_fb(){

        postToFeed();

    }

    function click_isread(){
        var isread = $("#click_isread");
        if(isread.hasClass('checked')){
            $("#isread").val(0);
            isread.removeClass('checked');
        }else{
            $("#isread").val(1);
            isread.addClass('checked');
        }
    }
	
	
</script>
<div class="body">
    <!--				<div class="crumb">
                                            <a href="#">專業體驗團</a> &gt;
                                            <a href="#">體驗報告</a> &gt;
                                            <strong>DOVE Anti - Hairfall shampoo</strong>
                                    </div>-->
    <div class="main fl">
        <div class="crumb">
            <a href="{#optimize_url('product', 'invite_list', 'mtype=1')#}">試用專區</a> &gt;
            <strong>試用邀請</strong>
        </div>
        <div class="ti_box b_box ti_box_try">
            <div class="hd">
                <h2 class="ir ht"><span>提交報告 TRIAL INVITATION</span></h2>
            </div>
            <div class="bd">
                <div class="areabox try">
                    <h2 class="at">試用專區</h2>
                    <div  style="margin: 15px">
                        <span >您正在申請： {#$product.name#} &nbsp;&nbsp; {#$product.cname#}</span>
                    </div>
                </div>
            </div>
        </div>

        <div id="fmbox" class="fmbox">
            <form id='form1' name='form1' action='/product.php?action=submit_application' method='post' target="iframe1">
                <input type='hidden' name='pid' value='{#$pid#}' />
                <input type='hidden' name='mtype' value='{#$mtype#}' />
                <input type='hidden' name='issubmit' value='true' />
                <input type='hidden' id="photo_path" name='photo_path' value='' />
                <div class="tabox">
                    <p>
                        <span class="ckbox">
                            <a href="javascript:void(0);" id="click_fb" class="ck" onclick="click_fb()"></a>
                            <input type="hidden" name="facebook" id="facebook" value=0  />
                            分享到facebook(可提高獲邀機會)
                        </span>
                        請輸入你想試用的原因<a class="more">（100字以內）</a>
                    </p>
                    <textarea class="textarea" name="reason" id="reason" onfocus="phide('mark1')"  onkeyup="checkLength(this)"></textarea>
                    <input type='hidden' id='reason_size' name="reason_size" value=0 />
                    <p class="tip"><em class="hack"></em>
                        <span  id="mark1"></span>
                    </p>
                </div>
                <!--
                <div class="ttbox sp">
                        <p>在iTRIAL的報告連結</p>
                    <input type="text" class="ipt" name="itrial_url" id="itrial_url" onfocus="phide('mark2')" />
                    <p class="tip"><em class="hack"></em>
                                                        <span  id="mark2"></span>
                                                </p>
                </div>
    
                <div class="ttbox sp">
                        <p>在其他網站的報告鏈接</p>
                    <input type="text" class="ipt" name="www_url2" id="www_url2" onfocus="phide('mark3')"/>
                    <p class="tip"><em class="hack"></em>
                                                        <span  id="mark3"></span>
                                                </p>
                </div>
                -->
                <div class="filebox sp">
                    <div class="imgbox"><p class="img_p"><span><img id='showimg' src="/data/p84x84.jpg" width=84></span></p></div>
                    <div class="infobox">
                        最近一個月的個人正面近照<br>
                        上載5M以下的相片(必須提供清晰正面照片)<br>
                        <p class="tip">
                            <em class="hack"></em>
                            <a class="btn_s btn_s_upload sfile" href="javascript:void(0);"> <strong>選擇檔案</strong><input id="mypic" name="mypic" onclick="c_pic();phide('mark4');" type="file" class="file_upload" /></a>

                        <div  id="mark4"style='height:15px'>&nbsp;</div>
                        </p>
                    </div>
                </div>

                {#foreach  from=$product.questions item=v key=k#}

                {#if $v.c eq 1#}
                <div class="ttbox sp"><p>{#$v.t#}</p>
                    <input type="text" class="ipt" name="ques[{#$k#}][a]" id="ques_{#$k#}" onfocus="phide('mark5_{#$k#}')"/>
                    <input type='hidden' name="ques[{#$k#}][t]" value="{#$v.t#}" />
                    <p class="tip"><em class="hack"></em><span  id="mark5_{#$k#}"></span></p>
                </div>
                {#else if $v.c eq 2#}
                <div class="ttbox sp"><p>{#$v.t#}</p>
                    <div class="infobox">
                        <p class="tip">
                            <em class="hack"></em>
                            <a class="btn_s btn_s_upload sfile" href="javascript:void(0);"> <strong>選擇圖片</strong></a>
                            &nbsp;&nbsp;<span id='qpicinfo_{#$k#}'></span><span  id="mark5_{#$k#}" style='height:15px'>&nbsp;</span>
                            <input q="qpic" id="qpic_{#$k#}" name="qpic_{#$k#}" onclick="qpic({#$k#});phide('mark5_{#$k#}');" type="file" class="file_upload" />
                            <input type='hidden' name="ques[{#$k#}][t]" value="{#$v.t#}" />
                            <input type='hidden' id="ques_{#$k#}" name="ques[{#$k#}][a]" value=""/>
                        </p>

                    </div>
                    <!--<div style='margin:5px'>
                            <img  id='qpic_show_{#$k#}' src="data/p84x84.jpg">
                    </div>-->
                </div>
                {#else if $v.c eq 3#}
                <div class="ttbox sp"><p>{#$v.t#}</p>
                    <ul class="option_list clearfix">
                        {#foreach  from=$v.o item=v1 key=k1#}
                        <li class="option"><input type="radio" name="ques[{#$k#}][a]" id="ques_{#$k#}_{#$k1#}" onfocus="phide('mark5_{#$k#}')" value='{#$v1#}'>{#$v1#}</li>
                        {#/foreach#}
                    </ul>
                    <input type='hidden' name="ques[{#$k#}][t]" value="{#$v.t#}" />
                    <p class="tip"><em class="hack"></em><span  id="mark5_{#$k#}"></span></p>
                </div>
                {#else if $v.c eq 4#}
                <div class="ttbox sp"><p>{#$v.t#}</p>
                    <ul class="option_list clearfix">
                        {#foreach  from=$v.o item=v1 key=k1#}
                        <li class="option"><input type="checkbox" name="ques[{#$k#}][a][]" id="ques_{#$k#}_{#$k1#}" onfocus="phide('mark5_{#$k#}')" value='{#$v1#}'>{#$v1#}</li>
                        {#/foreach#}
                    </ul>

                    <input type='hidden' name="ques[{#$k#}][t]" value="{#$v.t#}" />
                    <p class="tip"><em class="hack"></em><span  id="mark5_{#$k#}"></span></p>
                </div>
                {#/if#}
                {#/foreach#}

                <div class="tabox sp">
                    <p>條款及細則:</p>
                    <textarea class="textarea" readOnly="readOnly">{#htmlspecialchars_decode($product.trial_terms)#}</textarea>
                    <span class="ckbox ckbox2">
                        <a href="javascript:void(0);"  id="click_isread" class="ck" onclick="click_isread();phide('mark7');"></a>
                        <input type="hidden" id="isread" name="isread" value=0 />
                        本人已詳細閱讀隱私政策，並同意接受以上條款及細則
                    </span>
                    <p class="tip"><em class="hack"></em>
                        <span  id="mark7"></span>
                    </p>
                </div>

                <a href="javascript:void(0);" class="btn_s btn_s_fabiao" onclick='form1.submit();'><strong>發表</strong></a>
            </form>
        </div>
    </div>
    <!-- main-->
    <div class="sidebar">

        {#show_block('b2',1,'','sidebar_ad')#}
        {#show_block('b1',2,'','sidebar_function')#}
        {#show_block('b3',0,'','sidebar_search')#}
        {#show_block('b4',0,'','sidebar_workshop')#}
        {#show_block('b9',0,'','sidebar_tutorial b_box')#}
        {#show_block('b6',0,'','sidebar_facebook')#}
    </div>
    <!-- sidebar -->

</div><!--body-->
<div id="fullbg" ></div>
<div id='dialog'  class="apopbox popbox b_box" style="z-index: 60;	display:none;top:300px;">
    <div class="hd">
        <h2 class="ir ht"><span>提示信息 ALERT</span></h2>
        <a href='javascript:void(0);' onclick="closeLB();location.href='{#optimize_url('product', 'invite_inpage', 'mtype=1&pid='|cat:$product.id)#}';" class="popclose">close</a>
    </div>
    <div class="bd">
        <p>您已成功提交申請！</p>
        <p>獲邀會員名單將於「試用邀請」頁面上公佈，及個别以Email通知，敬請留意！</p>
        <a href="{#optimize_url('product', 'invite_list', 'mtype=1')#}" class="btn_b seemore_try"><strong>查看更多試用</strong></a>
    </div>
</div>
<div id='dialog1'   class="apopbox popbox b_box" style="top:300px;display:none;z-index:60;" >
    <div class="hd">
        <h2 class="ir ht"><span>提示信息 ALERT</span></h2>
        <a href='javascript:void(0);' onclick="closeLB()" class="popclose">close</a>
    </div>
    <div class="bd">
        <p>你還未綁定facebook</p>
        <a href="/member.php?action=login_facebook&toURL={#$thisUrl#}" class="btn_b_fb" target=_blank><strong>立即綁定Facebook</strong></a>
    </div>
</div>
<div style="top:400px;z-index:60;display:none;" class="apopbox popbox b_box" id="dialog_popup">
    <div class="hd">
        <h2 class="ir ht"><span>提示信息 ALERT</span></h2>
        <a class="popclose" onclick="closeLB();" style="cursor:pointer">close</a>            </div>
    <div class="bd">
        <p id="popupText"></p>
        <a class="btn_b btn_s_im_back" href="javascript:void(0);" onclick="closeLB();"><strong>立即返回</strong></a>            </div>
</div>
<div style="top:300px;z-index:60;display:none;" class="apopbox popbox b_box" id="dialog_limits">
    <div class="hd">
        <h2 class="ir ht"><span>提示信息 ALERT</span></h2>
        <a class="popclose" onclick="javascript:window.location.href='{#optimize_url('product', 'invite_inpage', 'mtype=1&pid='|cat:$pid)#}'" style="cursor:pointer">close</a>            </div>
    <div class="bd">
        <p>你還未成為試用專員，<a href="/member.php?action=regTrial&toURL={#$thisUrl#}">立即申請</a>，享受更多待遇！</p>
        <a class="btn_b btn_s_im_back" href="javascript:void(0);" onclick="javascript:window.location.href='{#optimize_url('product', 'invite_inpage', 'mtype=1&pid='|cat:$pid)#}'"><strong>立即返回</strong></a>            </div>
</div>
<div style="top:400px;z-index:60;display:none;" class="apopbox popbox b_box" id="dialog_popup1">
    <div class="hd">
        <h2 class="ir ht"><span>提示信息 ALERT</span></h2>
        <a class="popclose" onclick="javascript:window.location.href='{#optimize_url('product', 'invite_inpage', 'mtype=1&pid='|cat:$pid)#}'" style="cursor:pointer">close</a>            </div>
    <div class="bd">
        <p id="popupText1"></p>
        <a class="btn_b btn_s_im_back" href="javascript:void(0);" onclick="javascript:window.location.href='{#optimize_url('product', 'invite_inpage', 'mtype=1&pid='|cat:$pid)#}'"><strong>立即返回</strong></a>            </div>
</div>
<iframe id="iframe1" name="iframe1" style="display:none"></iframe>

<link rel="stylesheet" href="/js/ui/jquery-ui-1.8.8.custom.css"/>
<script src="/js/ui/jquery-ui-1.8.8.custom.min.js"></script>
<script>
    function postToFeed() {

        // calling the API ...
        var obj = {
            method: 'feed',
            //redirect_uri: '{#php#}echo DOMAIN;{#/php#}product.php?action=invite_inpage&mtype=1&pid={#$product.id#}',
            link: '{#php#}echo DOMAIN;{#/php#}product.php?action=invite_inpage&mtype=1&pid={#$product.id#}',
            picture: '{#php#}echo DOMAIN;{#/php#}{#$product._photo_url#}',
            name: '{#str_replace("'","’",$product.cname)#}',
            caption: '{#str_replace("'","’",$product.type_name)#}',
			description: '{#str_replace("'","’",str_replace(array("\r\n", "\n", "\r"),"",strip_tags(htmlspecialchars_decode($product.body))))#}'
        };

       

        FB.ui(obj, function(response){
            if(response['post_id']){
                 ajax_fb_ponits();
            }
        });
    }

    function checkLength(which) {
        $('#reason_size').val(which.value.length);
    }
    function showpop(text){
        $("#fullbg").fadeIn();
        $("#dialog1").fadeOut('slow');
        $("#dialog").fadeOut('slow');
        showLB('#dialog_popup',0);
        $("#popupText").html(text);
    }
    (function($){
        $.fn.imgIframeUpload = function(settings){
            var form;
            var iframe;
            var	self = this;
            var	selfId = self.attr('id');
            var	opts = {
                action: "/product.php?action=ajax&t=6&k="+settings['k'],
                callback: null
            };
            $.extend(opts, settings);

            form = $('<form method="post" action="' + opts.action + '" enctype="multipart/form-data" target="iframe-upload-' + selfId + '" style="display:none;"><input type="hidden" name="old_temp" /><input type="hidden" name="callback_script" value="' + (opts.callback ? ('parent.' + opts.callback + '($res);') : '') + '" /></form>');
            iframe = $('<iframe name="iframe-upload-' + selfId + '" frameborder="0" style="display:none;" src="about:blank"></iframe>');
            $('body').append(form).append(iframe);
            function fileChange(obj){
                obj.change(function(){
                    var fileInputClone = $(this).clone().val('').hide();
                    $(this).after(fileInputClone).attr('name', 'temp[]').removeAttr('id').appendTo(form);
                    fileInputClone.css('display', 'inline');
                    fileChange(fileInputClone);
                    form.submit();
                    $(this).remove();
                });
            }
            fileChange(self);
        }
    })(jQuery);
    function upPicCallback(res){
        if(res){
            if(res[0].code == 1){
                $('#photo_path').val(res[0].src);
                //$('#fileinfo').html(res[0].filename);
                $('#showimg').attr('src',res[0].thumb);
            }else{
                showpop(res[0].msg);
            }
        }
        $(window).focus();
    }
    function c_pic(){
        $('#showimg').attr('src',"/images/loading.gif");

        $('#mypic').imgIframeUpload({
            callback: 'upPicCallback'
        });
    }
    function qPicCallback(res){
        if(res){
            if(res[0].code == 1){
                $('#ques_'+res[0]['k']).val(res[0].src);
                $('#qpicinfo_'+res[0]['k']).html(res[0].filename);
                $('#qpic_show_'+res[0]['k']).attr('src',res[0].thumb);
            }else{
                showpop(data.msg);
                $('#showimg').attr('src',"/data/p84x84.jpg");
            }
        }
        $(window).focus();
    }
    function qpic(k){
        $("[q='qpic']").imgIframeUpload({
            callback: 'qPicCallback',
            k:k
        });
    }
	
	function showpop1(text){
        $("#fullbg").fadeIn();
        $("#dialog1").fadeOut();
        $("#dialog").fadeOut();
        $("#dialog_popup").fadeOut();
        $("#dialog_limits").fadeOut();
        showLB('#dialog_popup1',0);
        $("#popupText1").html(text);
    }
	
	$(function(){
		$.getJSON("/product.php?action=ajax&t=10",{pid:{#$pid#}},function(data){
		
            if(parseInt(data.login)==1){
                if(parseInt(data.email)==1){
                    if(parseInt(data.limit)==1){
                        if(parseInt(data.invite)==1){
                           // window.location.href="{#optimize_url('product', 'submit_application', 'mtype=1&pid='|cat:$pid)#}";
                        }else{
							showpop1(data.msg);
						}
                    }else{
                        showLB('dialog_limits',0);
                        //$("#limitsText").text(data.msg);
                    }
                }else{
                    showpop1("您的電郵地址尚未驗證，請先激活！<a class='pink' href='/member.php?action=resendActivation' target='_blank'>重發激活郵件</a>");
                }
            }else{
                $("#loginText").text("iTRIAL 會員登入 REGISTRATION");
                $("#login").attr("onClick","login('apply("+pid+")')");
                $("#login_type").attr("onClick","fnblogin('apply("+pid+")')");
                showLB('dialog',0);
            }
        });
	});
</script>
{#include file="footer.php"#}